Method and apparatus for alignment of images for template elimination

ABSTRACT

The present application concerns an improved method and apparatus for fine alignment for template elimination. This method involves the steps of dividing a filled-in template image and a reference template image into vertical bands of a given number w of columns of picture elements, employing the OCS algorithm to correlate lines in the vertical bands of the filled-in form, herein referred to as vertical input bands, to lines in the corresponding bands of the reference template image, and constructing a new input image in which each line is moved into its new position--this new image being used as input image, e.g. for template elimination.

TECHNICAL FIELD

The present invention relates to a method and apparatus for aligningimages, in particular the image of an empty template and the image of afilled-in template, in order to be able to separate the informationwritten into the template by eliminating the image of the emptytemplate. The invention is of particular interest in areas whereinformation filled into an invariant form is to be processed separatelyfrom the part of the image which does not contribute to the informationcontent as such.

BACKGROUND OF THE INVENTION

The handling of paper documents is a daily routine in today's officeenvironments. When trying to make the handling of documents--such asforms--more efficient, one has to digitise them in order to be able toemploy modern data processing means such as computers or datatransmission networks. Once a document is available to such a system, itis possible to load it in a storage from where it later can beretrieved. The storage and retrieval of documents is just one aspect inthis connection, the other, possibly more important aspect is thetreatment of the information contained in the documents.

The treatment of the information contained in documents generallyinvolves the acquisition of the information by a reading device, thetransformation of the acquired information into a machine-readable code,the storing of the coded information for later, and possibly repeatedprocessing, the actual processing of the information and finally theoutput of the results of the processing.

The acquisition of the information by a reading device, such as anoptical scanner, should be performed with sufficiently high resolutionlest the information content should become mutilated or partially lost.Reading devices usually produce a high volume of scan data which in turnrequire powerful computers for fast and reliable processing and a largememory capacity for storage. As a typical example, a page of the A4 size(279×210 mm), scanned at 100 pels/cm (where "pel" stands for pictureelement and is either a white or black dot), requires about 700 kBytesof storage space. Even a rather modest number of documents would callfor an unreasonable big memory.

Since most of an image of a filled-in form does not contribute to theinformation content, different methods have been developed for theseparation of the standard or constant part (CP), which is the emptyform, and the variable part (VP), which is the filled-in data. Such aseparation of the constant part (CP) and the variable part (VP), alsoknown as template elimination, has the following advantages:

Storage saving: it is possible to reconstruct many form images fromtheir variable parts (VP) superimposed with a single copy of theconstant part (CP). Typically, the varying part's (VP) size is just afraction of the size of the whole image, and 90% saving in storage arepossible.

Communication improvement: for the same reasons as above, separating theconstant (CP) and variable parts (VP) saves up to a magnitude incommunication volume and thus eliminates one of the common bottlenecksof forms processing systems.

Higher accuracy in optical character recognition (OCR): in certainsituations the constant part (CP) of a form might interfere withautomatic character recognition. Having access to the variable part (VP)alone, frequently eliminates this problem.

One method for the elimination of the constant part (CP), i.e. the formas such, has for example been implemented and reported by D. E. Nielsenet al., in "Evaluation of Scanner Spectral Response for InsuranceIndustry Documents", 16/A44 NCI Program, Working Paper No. 2, May 1973.This method, also known as "dropout ink" technique, is based on the ideato use a special colour ink when printing a form which is transparent toconventional scanners. If a completed form of this type is scanned, thebasic pattern (i.e. CP) would be invisible to the scanner, and only thevariable part (VP) would be entered into the computer. An evidentdisadvantage of this approach is that the use of special-ink-sensitivescanners would exclude the application of this approach to existingarchives. Also, the use of special ink is certainly more cumbersome andcostly. It is a further disadvantage of the "dropout ink" technique thatthere are customers who wish to eliminate the form background, but donot have any influence on how the forms they get are printed, and whatkind of colour has been used for printing.

Another approach for the separation of the form background from thefilled-in information is disclosed in European patent application EP-A-0411 231 (U.S. Pat. No. 5,182,656) with title "Method for Compressing andDecompressing Forms by Means of very large Symbol Matching". Accordingto this approach, samples of an empty form (CP) are pre-scanned and thedata obtained digitised and stored in a computer memory to create aforms library. The original, filled-in form (F) to be compressed is thenscanned, the data obtained digitised and the retrieved representation ofthe empty form (CP) is then subtracted, the difference being the digitalrepresentation of the variable part (VP), i.e. the filled-ininformation.

In order to perform such form elimination, it is necessary to preciselyalign the input form image (F) with an image of the empty template (CP).Even when the input form image is globally aligned with thetemplate--i.e. there are no offset, skew, or scale differences--thereusually are local distortions that must be straightened out before thetemplate (i.e. the constant part CP) can be dropped out. Such localdistortions are frequently the result of inconsistent scannerperformance, or distortions from photocopying.

A method to compute fine registration, i.e. to align the constant part(CP) with respect to the variable part (VP) of an image is described inEuropean patent applications EP-A-0 411 231 (U.S. Pat. No. 5,182,656),which has already been mentioned above, and in EP-A-0 411 232 (U.S. Pat.No. 5,204,756) with title "Method for High-Quality Compression of BinaryText Images". Assuming that the local distortions are small, andpiecewise linear, both the input (F) and the template images (CP) arebroken into small blocks and histogram correlation is used to find therelative offsets of corresponding blocks. A distinct consistencypreserving process is employed to ensure there are no conflicts betweenthe offsets computed for different blocks. In cases where there is notenough information in the histogram of a block, the offsets of theneighbouring blocks are used to compute its transformation.

In practice, the above technique usually works quite well, but improvedreliability is required in some special cases:

Distortions accumulated through several iterations of copying a formcome up against limiting factors of the existing technique.

With some scanners, using the same form both as template and as inputdoes not result in a clean image after dropout.

Users have reported artifacts in form reconstruction in areas that arevery densely filled, and which are therefore very sensitive to minuteregistration errors.

There are some reports of severe registration errors when the quality ofthe template scan is poor.

It has been found that the known techniques for template elimination arenot adequate for dealing with images having non-linear distortions.

DISCLOSURE OF THE INVENTION

It is an object of the present invention to improve the handling ofimages with non-linear distortions in order to be able to make knowntemplate elimination techniques more reliable.

It is an object of the present invention to overcome the localdistortions in order to be able to achieve a fine alignment of the inputimage (F) with the empty reference template image (CP).

It is a further object of the present invention to provide a method andapparatus for template elimination with improved robustness of the finealignment process.

The above objects have been achieved in that an optimal correspondencesubsequence (OCS) algorithm has been employed to improve the robustnessof the fine alignment process. The method in accordance with thisinvention involves the steps of correlating lines in a referencetemplate image to lines in a filled-in template image by findingcorresponding pairs of projections in one direction of said lines in thereference template image and the filled-in template image, determiningthe displacement of the two projections of lines of each pair in adirection perpendicular to said direction of projection and evaluatingthe number of rows or columns the picture elements of each line of thefilled-in template image has to be shifted to achieve a match betweensaid pairs of projections, and generating a new input image (26) byshifting the picture elements of lines of the filled-in template imageperpendicular to said direction of projection as determined in the laststep.

In another advantageous embodiment of the present invention, the samesteps are now repeated in a direction 90 degrees rotated with respect tothe direction of projection of the above process.

In a further embodiment, the filled-in template image and the referencetemplate image are divided into bands before carrying out the aboveprocess. This method has the advantage that it can easily cope withskewed lines.

BRIEF DESCRIPTION OF DRAWINGS

The invention is described in detail below with reference to thefollowing drawings:

FIG. 1 is a flowchart illustrating the storage and retrieval ofreference template images in a forms library and showing the horizontalfine alignment in accordance with the present invention.

FIG. 2 shows images of a reference template and of an input template.

FIG. 3 shows the reference template image and the input template imageof FIG. 2 divided into vertical bands, according to the presentinvention.

FIG. 4 shows the reference template of FIG. 2 and a new input imageobtained according to the present invention.

FIG. 5 is a flowchart showing the vertical fine alignment in accordancewith the present invention.

FIG. 6 is a schematic block diagram of an apparatus in accordance withthe present invention.

MODES FOR CARRYING OUT THE INVENTION

Prior to eliminating the constant part (CP) of a filled-in template,known as template elimination technique, the image of an empty template,referred to as reference template image (CP), has to be preciselyaligned with respect to-the image of the filled-in template. Especiallylocal distortions, in particular non-linear distortions, have adetrimental influence on the accuracy of this fine alignment. The betterthe alignment of the constant part (CP) with respect to the filled-intemplate (F) is, the better the result of the template eliminationprocess will be. To improve the robustness of the whole fine alignmentprocess, an algorithm known as optimal correspondence subsequence (OCS)algorithm has been adopted. This optimal correspondence subsequencealgorithm has already been described in context with stereo matching,which is an infinite alphabet penalty minimisation problem. This problemof substring matching by means of the OCS algorithm has been describedin the article "Optimal Correspondence of String Subsequences", Y. P.Wang et al., IEEE Transaction on Pattern Analysis and MachineIntelligence, Vol. 12, No. 11, November 1990, pp. 1080-1087.

In the following sections the use of the modified OCS algorithm--i.e theoptimal subsequence correspondence for form recognition--in connectionwith fine alignment for template elimination is set out in detail. Notethat the formulation of the below problem is somewhat different thanstandard, in that the function f(i,j,a,b) takes the indices i and j asarguments in addition to the sequence elements a and b. This notationpermits some flexibility in controlling unwanted matches.

Given are two sequences of picture elements (pels) A={a₀,a₁, . . . ,a_(N) }, B={b₀,b₁, . . . , b_(M) }, and a function f(i,j,a,b) such thatf(i,j,a,b)≧0 for all numeric arguments. The function f(i,j,a,b) isemployed to evaluate the quality of the match between the elements a andb. The OCS is a set of index pairs P 2! such that the sum ##EQU1## ismaximum. Said set P 2! comprises the following index pairs

    P={(j.sub.0, k.sub.0),(j.sub.1,k.sub.1), . . . , (k.sub.L, k.sub.L)} 2!

such that

    0≦j.sub.0 <j.sub.1 <. . . <j.sub.L ≦N

    0≦k.sub.0 <k.sub.1 <. . . <k.sub.L ≦M,

L being the number of matched elements of the sequences of elements Aand B. At the end of the above steps the maximal sum 1! and the sequenceof index pairs P have been produced as output. The OCS algorithm asherein used is addressed in more detail below.

By the following steps 1)-4) a matrix S is calculated in which s(N,M) isthe score of the OCS problem with A={a₀. a₁. . . . a_(N) }. and B={b₀.b₁. . . . . , b_(M) }.

1) S(0,0)=f(a₀, b₀)

2) for i=1 to N-1 s(i,0)=MAX{s(i-1,0), f(i,0, a_(i), b₀)}

3) for j=1 to M-1 s(0,j)=MAX{s(0,j-1), f(0.j, a₀, b_(j))}

4) for i=1 to N-1 for j=1 to M-1

    s(i,j)=MAX{s(i,j-1), s(i-1,j), s(i-1,j-1)+f(i,j, a.sub.i, b.sub.j)}

In steps 5) through 9) the sequence of index pairs of set P arecalculated as given by:

5) i=N-1, j=M-1

6) while i≧0 and 1≧0

7) if i>0 and s(i-1,j)=s(i,j)i=i-1 else

8) if j>0 and s(i,j-1)=s(i,j) j=j-1 else

9) if s(i,j)>0 insert (i,j) at the beginning of P i=i-1 j=i-1.

s(N-1,M-1) is the return value of the modified OCS algorithm, and P hasthe required indices.

The mathematical background of the present invention has been set out indetail above. In the following sections, the method in accordance withthe invention is described in connection with an example. The steps ofthe present method and some preparatory steps 1-4 are illustrated in theflowcharts given in FIGS. 1 and 5.

It is schematically illustrated in FIG. 1 that a reference template (CP)can either be scanned (box 1) and taken as reference input for thepresent fine alignment process, or be stored in a forms library. Thestorage in, and retrieval from such a library is indicated by steps 2,3,and 4.

As shown in FIG. 2, there is an image of an empty reference template 20(CP) given, which consists of 12 rows of pels and 24 columns of pels.For the sake of simplicity, an underlying grid is shown in this and thesubsequent figures and each black pel is shown as an X in said figures.It is to be noted that when referring to horizontal and vertical, eitherthe direction parallel to the rows and parallel to the columns of animage are meant, or vice versa.

On the left hand side of the empty reference template 20 image (CP), thenumber of black pels per row is indicated. This sequence of numbers canbe described by A={0, 19, 0, 0, 19, 0, 1, 2, 0, 19, 0, 0}. Templateimage 20 is usually stored in a storage (either a forms library or awork buffer) from where it can be easily retrieved (step 4). Steps 1-4of scanning and storing the empty template 20 have not necessarily beencarried out directly before carrying out all other steps illustrated inFIG. 1. The creation and maintenance of a database with adequatereference templates, i.e. a database comprising different empty forms(CP), is not addressed herein.

As first step of the present invention, the template to be processed(usually a filled-in form) is scanned by an appropriate scanner and animage 21 (F) of this template is obtained. The image 21 will hereinafterbe referred to as input image. The respective step is shown in FIG. 1,box 10, and the digitised input image 21 itself is shown in FIG. 2.Since the content of this template, i.e. the information which isusually filled in, is not relevant when describing the fine alignmentaccording to the present invention, an empty template similar to the onewhich was already used as reference template (CP) has been scanned. Itis evident, when comparing the two images 20 and 21, that both imagesslightly differ due to inaccuracies introduced by the scanner. Thesecond image 21 has only 11 rows and 24 columns of pels and some of theblack pels are either missing or dislocated. The number of black pelsper row of the input image is described by the sequence of pels B={0,18, 1, 0, 10, 8, 0, 3, 0, 0, 18}. The number of pels per row of thereference image 20 in comparison to those of the input image 21 isillustrated in Table 1.

                  TABLE 1                                                         ______________________________________                                        number of black pels of the reference and input template                      ______________________________________                                        row                                                                           A    0     19     0   0    19  0    1   2    0   19  0                                                     0                                                                             B 0 18 1 0 10 8 0 3 0 0 18                       ______________________________________                                    

Before elimination of the constant part (CP) of the input image 21, thelocal distortions have to be cleared and the input image 21 has to beprecisely aligned with respect to the reference image 20.

According to the present invention, both the reference image 20 and theinput image 21 are now divided into vertical bands, i.e. into bandscomprising several columns of pels. This step is represented by box 11in FIG. 1. As illustrated in FIG. 3, the reference image 20 is dividedin two vertical reference bands 22 (CP_(A)) and 23 (CP_(B)). The inputimage 21 is divided into two vertical input bands 24 (F_(A)) and 25(F_(B)). The number of black pels of each row of these four verticalbands is given in FIG. 3.

Next, the matching of each of the vertical input bands 24, 25 of theinput image 21 and the reference bands 22, 23 of the reference image 20is performed by employing the modified OCS algorithm. This step isindicated by reference number 12. In order to correlate the horizontalprojection of lines in the vertical input bands 24, 25 to lines in thevertical reference bands 22 and 23, the OCS is employed. It determinesthe vertical offset of said lines in the vertical bands.

The sequences of black pels (A_(A),A_(B) and B_(A),B_(B) in the presentexample) are the horizontal projections of the lines in the verticalbands, and f(i,j,a,b) is the function that evaluates the quality of thematch between the elements of these sequences of black pels. In Table 2,the matching of the vertical reference band 22 and the vertical inputband 24 is illustrated. The "-" character denotes a missing entry. Itimplies deletion of the corresponding entry in Table 3.

                  TABLE 2                                                         ______________________________________                                        matching of CP.sub.A and F.sub.A                                              ______________________________________                                        A.sub.A                                                                           0     8      0   0   8   0    0   2   0   --   8                                                     0   0                                                                         B.sub.A                                                                           0 10 1 0 9 0 0 0 0 0 8                         ______________________________________                                    

The number of matched elements is L=10. The matching of the sequences ofpels A_(B) and B_(B) of the vertical bands CP_(B) and F_(B) isillustrated in Table 3. The number of matched elements is L=10, too.

                  TABLE 3                                                         ______________________________________                                        matching of CP.sub.B and F.sub.B                                              ______________________________________                                        A.sub.B                                                                           0     11     0   0   --  11   0   1   0   0    11                                                    0   0                                                                         B.sub.B                                                                           0 8 0 0 1 8 0 3 0 0 10                         ______________________________________                                    

In accordance with the above OCS algorithm, new vertical positions forthe lines in said vertical input bands F_(A) and F_(B) are defined. Anew input image 26 (F) in which each line is now moved into its newposition is constructed next. This reconstruction by vertical shifts isshown as step 13 in FIG. 1. The new input image 26 (F), FIG. 4, is usedas input image for all further steps, i.e. either for the horizontalfine alignment steps of FIG. 5, or directly for template elimination(box 14, FIG. 1).

The fine alignment in accordance with the present invention can noweither be finished, said new input image 26 (F) being taken as inputimage for a conventional template elimination process 14, or the steps50-52, FIG. 5, might be carried out to further improve the alignment ofreference template image 20 (CP) and new input image 26 (F).

Fine alignment in only one direction, e.g. either parallel to the rowsof pels or parallel to the columns of pels, might lead to satisfyingresults in cases where for example a FAX machine is used for reading afilled-in form which causes mainly distortions along the vertical axis.These kind of distortions are sometimes caused by mechanicalimperfections of the motor.

The horizontal fine alignment, see steps 50 through 52, is addressed inthe following. Since the basic principle of the matching process hasalready been described above by way of example, steps 50-52 are notdescribed in all details.

The new input image 26 (F) and the reference template image 20 (CP) arenow divided into horizontal bands of a given `heights` h (h=number ofrows of pels). In the present example the total length of a template isonly 24 pels and h=12 pels/band could for instance be chosen as`heights` of the horizontal bands. The step of dividing said new inputimage 26 (F) and the reference image 20 (CP) into horizontal bands isdepicted as step 50 in the flowchart of FIG. 5.

Next, the OCS algorithm is used to correlate lines in the horizontalinput bands to lines in the horizontal reference bands and to determinethe horizontal offset of vertical lines in said bands. A_(a), A_(b) andB_(a), B_(b) are now the vertical projections of the lines in thehorizontal reference bands and the horizontal input bands, respectively.This step is illustrated by box 51 in FIG. 5. By means of a matchingfunction f(i,j,a,b), the quality of the match between the sequencesA_(a) and B_(a), as well as the match between A_(b) and B_(b) isevaluated, as described in context with the matching step 12.

Finally, a new input image (F) is constructed by moving the verticallines in the horizontal input bands to their optimum position, see step52 in FIG. 5.

The above algorithm can be speeded-up by the following optimisationmeasures:

1. Performing either the first matching process, i.e. the alignment ofhorizontal lines by means of vertical bands, or the second matchingprocess, i.e. the alignment of vertical lines by means of horizontalbands,

2. Not evaluating the parts of S where i<j+max₋₋ diff or j<i+max₋₋ diff,where max₋₋ diff is application dependent.

3. Not evaluating the rest of row i if s(i,j) is big enough with respectto the maximal value in the row i-1, where big enough is applicationdependent.

4. Not evaluating the rest of column j if s(i,j) is big enough withrespect to the maximal value in column j-1, where big enough isapplication dependent.

When processing documents consisting for instance of A4 pages, dividingeach page into vertical bands of a `width` w=250 pels and intohorizontal bands of a `height` h=250 pels has shown good results. It isto be noted that the matching function f(x,y) used in the present OCSalgorithm can be modified. f(x,y)=|w-(x-y)|, f(x,y)=|h-(x-y)| andf(x,y)=1+MIN(x,y) are examples for the matching function to be used.

An exemplary system for template elimination is schematicallyillustrated in FIG. 6. This system comprises a scanner 61, a formslibrary 62, a work buffer 63, and a fine alignment unit 65 being partof, or being controlled by, a processor 64. All these circuits andelements are interconnected by a bus 66, which might for example be anAT bus. According to the present invention, a reference template image,which might have been stored in said forms library 62, is fed to saidfine alignment unit 65 on request of the processor 64. A filled-intemplate is scanned by scanner 61, and its image forwarded to the workbuffer 63. From there it can be retrieved on request. The fine alignmentunit 65 now carries out the steps in accordance with the presentinvention by interaction with the processor and the storages 62, 63.Finally, it stores the new input image (F) in said work buffer 63, fromwhere it can be retrieved for template elimination.

It is evident, that instead of basing the present fine alignment processon black pels and sequences of black pels, white pels and the respectivesequences of white pels might be used. It is furthermore to be notedthat under certain circumstances no division of images is necessary,i.e. only one band of rows or columns is processed in accordance withthe present invention. The rows of pels as herein used are eitherparallel to the shorter edge of a sheet of paper or perpendicular tothis edge. The same applies to the columns of pels which are orthogonalto the rows.

The present technique is significantly more robust than conventionaltemplate elimination techniques. It was tested with many examples of theold techniques failures and proved superior with respect to thecompression achieved, visual quality, and speed.

I claim:
 1. A method of aligning a reference template image with afilled-in template image comprising the steps of:a) correlating lines insaid reference template image to lines in said filled-in template imageby finding corresponding pairs of projections in a first direction ofsaid lines; b) determining a displacement of the two projections oflines of each of said corresponding pairs in a second directionperpendicular to said first direction and evaluating the number ofpicture elements each line of said filled-in template image has to beshifted to achieve a match between said pairs of projections, said stepof determining including using f(a,b)=1+MIN(a,b), where a representspicture elements in each of said lines in said reference template and bpicture elements in each of said lines in said filled-in template, as amatching function to evaluate quality of said match; and c) generating anew input image by shifting the picture elements of lines of saidfilled-in template image perpendicular to said first direction using thedetermined displacement.
 2. The method according to claim 1 whereineither f(a,b)=|w-(a-b)| or f(a,b)=|h-(a-b)| is used as said matchingfunction, a representing picture elements in each of said lines in saidreference template, b representing picture elements in each of saidlines in said filled-in template, w and h being the width and height,respectively, of said reference and said filled-in templates.
 3. Themethod according to claim 2, further comprising the steps of:a)correlating lines in said reference template image to lines in said newinput image by finding corresponding pairs of projections of said linesin said reference template image and said new input image in said seconddirection; b) determining a displacement of the two projections of linesof each said pair in said first direction and evaluating the number ofpicture elements each line of said new input image has to be shifted toachieve a match between said pairs of projections; and c) generating anew input image by shifting the picture elements of lines of saidfilled-in template image in said first direction using the determineddisplacement.
 4. The method according to claim 3, wherein said referencetemplate image is divided into reference bands having a plurality ofrows of picture elements, and said new input image is divided intocorresponding input bands having a plurality of rows of pictureelements, prior to carrying out steps a)-c) of claim 2, these stepsbeing carried out separately for each reference band and itscorresponding input band.
 5. The method according to claim 4 whereinprojections of lines in a direction parallel to said rows are determinedby summing the number of black picture elements of each row of therespective image or band, and wherein projections of lines in adirection parallel to said columns are determined by summing the numberof black picture elements of each column of the respective image orband.
 6. The method according to claim 2, wherein said referencetemplate image is divided into reference bands having a plurality ofcolumns of picture elements, and said filled-in template image isdivided into corresponding input bands having a plurality of columns ofpicture elements, prior to carrying out steps a)-c) of claim 1, thesesteps being carried out separately for each reference band and itscorresponding input band.
 7. The method according to claim 2 whereinsaid new input image and said reference template are taken as input fortemplate elimination to separate the lines of said reference templatefrom the contents of said filled-in template.
 8. An apparatus for thealignment of a reference template image and a filled-in template imagehaving a processor and a storage for storing said reference templateimage and said filled-in template image, said apparatus comprising:meansfor correlating lines in said reference template image by findingcorresponding pairs of projections in a first direction of said lines;means for determining the displacement of the two projections of linesof each said corresponding pair in a second direction, said seconddirection being perpendicular to said first direction and means forevaluating the number of picture elements of each line said filled-intemplate image has to be shifted to achieve a match between pairs ofprojections, said determining means including means for usingf(a,b)=1+MIN(a,b), where a represents picture elements in each of saidlines in said reference template and b picture elements in each of saidlines in said filled-in template, as a matching function to evaluatequality of said match; and means for generating a new input image byshifting the picture elements of lines of said filled-in template imagein said second direction as determined by said determining means.
 9. Theapparatus of claim 8 wherein f(a,b)=|w-(a-b)| or f(a,b)=|h-(a-b)|, arepresenting picture elements in each of said lines in said referencetemplate, b representing picture elements in each of said lines in saidfilled-in template, w and h being the width and height, respectively, ofsaid reference and said filled-in templates, is used as said matchingfunction.
 10. The apparatus according to claim 9 furthercomprising:means for correlating lines in said reference template imageto lines in said new input image by finding corresponding pairs ofprojections of said lines in said reference template image and said newinput image in said second direction; means for determining thedisplacement of the two projections of lines of each said pair in saidfirst direction and means for evaluating the number of lines the pictureelements of said new input image has to be shifted to achieve a matchbetween said pairs of projections; and means for generating a new inputimage by shifting the picture elements of said filled-in template imagein said first direction as determined by said determining means.
 11. Theapparatus according to claim 10 further comprising means for dividingsaid reference template image into reference bands having a plurality ofrows of picture elements, and for dividing said new input image intocorresponding input bands having a plurality of rows of pictureelements.
 12. The apparatus according to claim 9 further comprisingmeans for dividing said reference template image into reference bandshaving a plurality of columns of picture elements, and for dividing saidfilled-in template image into corresponding input bands having aplurality of columns of picture elements.
 13. A method of aligning afilled-in template image with a reference template image, said filled-inand said reference template image each having a plurality of rows andcolumns of pixel elements, said method comprising the steps of:matchingeach row of said filled-in template image to a corresponding row of saidreference template image; determining whether there exists an offsetbetween each row of a pair of matched rows, said step of determiningincluding the step of using f(a,b)=1+MIN(a,b), where a representspicture elements in each of said lines in said reference template and bpicture elements in each of said lines in said filled-in template, as amatching function to evaluate quality of said match; and adjusting saidrow of said filled-in template to eliminate said offset if said offsetexists.
 14. The method according to claim 13 wherein f(a,b)=|w-(a-b)| orf(a,b)=|h-(a-b)|, a representing picture elements in each of said linesin said reference template, b representing picture elements in each ofsaid lines in said filled-in template, w and h being the width andheight, respectively, of said reference and said filled-in templates, isused as said matching function.
 15. The method of claim 14 furthercomprising the steps of:matching each column of said adjusted filled-inimage to a corresponding column of said reference template image;determining whether there exists an offset between each column of a pairof matched columns; and adjusting said column of said filled-in templateto eliminate said offset if said offset exists.
 16. The method of claim15 further comprising the step of using one of two matching functions toevaluate quality of the column matches between the reference templateimage and the filled-in image:

    f(a,b)=1+MIN(a,b),

or

    f(a,b)=|w-(a-b)|

and

    f(a,b)=|h-(a-b),

a representing picture elements in each of said lines in said referencetemplate, b representing picture elements in each of said lines in saidfilled-in template, w and h being the width and height, respectively, ofsaid reference and said filled-in templates.
 17. An apparatus foraligning a filled-in template image with a reference template image,said filled-in and said reference template image each having a pluralityof rows and columns of picture elements, said apparatus comprising:meansfor matching each row of said filled-in template image to acorresponding row of said reference template image; means fordetermining whether there exists an offset between each row of a pair ofmatched rows, said step of determining including the step of usingf(a,b)=1+MIN(a,b), where a represents picture elements in each of saidlines in said reference template and b picture elements in each of saidlines in said filled-in template, as a matching function to evaluatequality of said match; and means for adjusting said row of saidfilled-in template to eliminate said offset if said offset exists. 18.The apparatus of claim 17 wherein f(a,b)=|w-(a-b)| or f(a,b)=|h-(a-b)|,a representing picture elements in each of said lines in said referencetemplate, b representing picture elements in each of said lines in saidfilled-in template, w and h being the width and height, respectively, ofsaid reference and said filled-in templates, is used as said matchingfunction.
 19. The apparatus of claim 18 further comprising:means formatching each column of said adjusted filled-in image to a correspondingcolumn of said reference template image; means for determining whetherthere exists an offset between each column of a pair of matched columns;and means for adjusting said column of said filled-in template toeliminate said offset if said offset exists.
 20. The apparatus of claim17 further comprising means for using one of two matching functions toevaluate quality of column matches between the reference template imageand the filled-in image:

    f(a,b)=1+MIN(a,b),

or

    f(a,b)=|w-(a-b)|

and

    f(a,b)=|h-(a-b)|,

a representing picture elements in each of said lines in said referencetemplate, b representing picture elements in each of said lines in saidfilled-in template, w and h being the width and height, respectively, ofsaid reference and said filled-in templates.